/**
 * 登录用户状态管理
 */
import { defineStore } from 'pinia';
import { listMesMaterialInventorys } from '@/api/mes/mesMaterialInventory';

export const useMaterialStore = defineStore('material', {
  state: () => ({
    materialList: [],
  }),
  actions: {
    async fetchMaterialList() {
      listMesMaterialInventorys().then((data) => {
        this.materialList = data.rows || []
        sessionStorage.setItem('materialList', JSON.stringify(data.rows))
      })
    },
    /**
     * 更新用户信息
     */
    setMaterialList(data) {
      this.materialList = data
    },
  },
  getters: {
    /** 需要缓存的路由组件 */
    getMaterialList() {
      return this.materialList;
    }
  },
});
